package com.zhiyou.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhiyou.dao.ActivityMapper;
import com.zhiyou.entity.Activity;
import com.zhiyou.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    ActivityMapper activityMapper;


    @Override
    public List<Activity> getAll(String field,String keyword) {
        List<Activity> list = null;
        if (field!=null){
            Example example = new Example(Activity.class);
            Example.Criteria criteria = example.createCriteria();
            System.out.println(field+keyword);
            criteria.andLike(field,"%"+keyword+"%");
            list = activityMapper.selectByExample(example);
            return list;
        }
        list = activityMapper.selectAll();
        return list;
    }

    @Override
    public void add(Activity activity) {
        int insert = activityMapper.insert(activity);
    }

    @Override
    public void delete(Integer aId) {

        activityMapper.deleteByPrimaryKey(aId);
    }

    @Override
    public void update(Activity activity) {
        activity.setaTaketime(new Date());
        activityMapper.updateByPrimaryKey(activity);
    }
}
